<?php
class MemberAction extends Action
{
	public function preMethod()
	{
		R("Mayijie/check_admin");
		$perm_key = session('admin_perm');
		$perm_arr = explode(",",$perm_key);
		if(!in_array(9,$perm_arr)){
			$this->error("无权操作");
		}
	}

	public function index(){
		$Member=M('Member');
		import("ORG.Util.Page");
		$count=$Member->count();
		$Page=new Page($count,10);

		$member=$Member->limit($Page->firstRow.','.$Page->listRows)->order('member_id desc')->select();

		$Page->setConfig('header', '条');
		$Page->setConfig('prev', '<img src="__APP__/statics/up.gif">');
		$Page->setConfig('next', '<img src="__APP__/statics/down.gif">');
		$Page->setConfig('theme', "%upPage%  %linkPage% %downPage%  共%totalPage%页");
        $page = $Page->show();
		$this->assign("member", $member);
		$this->assign("page", $page);
		$this->display();
	}
	public function menu(){
		$this->display();
	}

	public function member_edit(){
		$Member=M('Member');
		$map['member_id']=$this->_get('id');
		$this->member=$Member->where($map)->find();
		$action=$this->_get('action');
		if($action=='save'){
			$map2['uname']=$this->_post('uname');
			$pwd=$this->_post('pwd');
			if(!empty($pwd)){
				$data['password']=md5($pwd);
			}
			$data['tel']=$this->_post('tel');
			$data['email']=$this->_post('email');
			$data['mobile']=$this->_post('mobile');
			$data['wallet']=$this->_post('wallet');
			$data['disable']=$this->_post('disable');
			if($Member->where($map2)->save($data)){
				$this->success('修改成功！');
			}else{
				$this->error("修改失败！");
			}
		}else{
		    $this->display();
		}
	}

	public function del_member(){
		$Member=M('Member');
		$map['member_id']=$this->_get('id');
		if($Member->where($map)->delete()){
			echo 1;
		}else{
			echo 0;
		}
	}

}